package io.renren.modules.report.service.impl;

import io.renren.modules.echarts.dao.TeacherEvaluationChartsDao;
import io.renren.modules.echarts.entity.AttendanceDate;
import io.renren.modules.echarts.entity.PieEntity;
import io.renren.modules.echarts.entity.TeacherEvaltionPieEntity;
import io.renren.modules.echarts.service.AttendenceChartsService;
import io.renren.modules.echarts.service.Impl.TeacherPortraitServiceImpl;
import io.renren.modules.echarts.service.TeacherEvaluationChartsService;
import io.renren.modules.echarts.service.TeacherPortraitService;
import io.renren.modules.jxgk.entity.ClassDiaryEntity;
import io.renren.modules.jxgk.service.ClassDiaryTableService;
import io.renren.modules.report.dao.ReportDao;
import io.renren.modules.report.entity.StudentAttTable;
import io.renren.modules.report.entity.workLoadPointline;
import io.renren.modules.report.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    ReportDao reportDao;
    @Autowired
    TeacherEvaluationChartsService teacherEvaluationChartsService;
    @Autowired
    TeacherPortraitService teacherPortraitService;
    @Autowired
    AttendenceChartsService attendenceChartsService;

    @Autowired
    TeacherPortraitServiceImpl t;

    @Autowired
    ClassDiaryTableService classDiaryService;

    @Override
    public Map getResult(Map<String, Object> params) {
//        String valid=t.ValidDatesConverter(params);
//        //加入肯德基豪华套餐
//        params.put("ValidDates",valid);
        String nowGrade= getNowGrade();//在校年级
        params.put("nowGrade",nowGrade);
        Map<String,Object> result=new HashMap();
        Integer classTotal=reportDao.getclassTotal(params);result.put("classTotal",classTotal);
        Integer allClassTotal=reportDao.getAllclassTotal(params);result.put("allClassTotal",allClassTotal);
        Integer studentTotal=reportDao.getStudentTotal(params);result.put("studentTotal",studentTotal);
        Integer allstudentTotal=reportDao.getAllstudentTotal(params);result.put("allstudentTotal",allstudentTotal);
        Integer teacherTotal=reportDao.getTeacherTotal(params);result.put("teacherTotal",teacherTotal);
        Integer allteacherTotal=reportDao.getAllteacherTotal(params);result.put("allteacherTotal",allteacherTotal);
        Integer chidaozaotuiTotal=reportDao.getChidaozaotuiTotal(params);result.put("chidaozaotuiTotal",chidaozaotuiTotal);
        List hasCourse =teacherEvaluationChartsService.getTeacherWorkEcharts(params);result.put("hasCourse",hasCourse);
        //出勤情况饼状图
        List<AttendanceDate> teacherAttendancePie=teacherPortraitService.getTeacherAttendancePie(params);result.put("teacherAttendancePie",teacherAttendancePie);
        //  Map<String,Object> hasCourseTime =teacherEvaluationChartsService.getTeacherWorkTimeRate(params);result.put("",);
        //迟到前十名
        Map  chidao=teacherPortraitService.getTeacherChidao(params);result.put("chidao",chidao);
        //早退前十名
        Map<String,List> zaotui=teacherPortraitService.getTeacherZaotui(params);result.put("zaotui",zaotui);
        Map<String,Object> rank =teacherEvaluationChartsService.getAverageTeacheingTimeRanking(params);result.put("rank",rank);

        Integer learningClassTotal=reportDao.getLearningClassTotal(params);result.put("learningClassTotal",learningClassTotal);
        Integer coureTotal=reportDao.getLearningCourseTotal(params);result.put("coureTotal",coureTotal);

        Double teacherTime=reportDao.getTeacherTime(params);result.put("teacherTime",teacherTime);
        Double allSchoolTeacherTime=reportDao.getAllSchoolTeacherTime(params);result.put("allSchoolTeacherTime",allSchoolTeacherTime);
        //相符率饼状图
        List<TeacherEvaltionPieEntity>  xiangfuRate=teacherEvaluationChartsService.getiMatchContentRate(params);result.put("xiangfuRate",xiangfuRate);
        //到课率
        Map  coincidenceRate=attendenceChartsService.studentAttendanceRate(params);result.put("coincidenceRate",coincidenceRate);
        //专业到课率排名
        Map<String,Object> pressionRate =attendenceChartsService.getAttendanceProfessionRankingFirstTen(params);result.put("pressionRate",pressionRate);
        //班级到课率排名
        Map<String,Object> ClassRate =attendenceChartsService.getAttendanceClassRankingFirstTen(params);result.put("ClassRate",ClassRate);

        //学院出勤情况横向比
        Map<String,Object> collegeTeacherEvaltion =teacherPortraitService.getTeacherAttendanceOfCollege01(params);result.put("collegeTeacherEvaltion",collegeTeacherEvaltion);
        //出勤情况纵向比
        Map<String,Object> teacherAttendanceTimePie =teacherPortraitService.getTecaherAttendanceCollegeHorizontalComparison(params);result.put("teacherAttendanceTimePie",teacherAttendanceTimePie);
        List< ClassDiaryEntity > teacherAttTable = classDiaryService.queryListChiDaoZaotuiOfOurStudent(params);result.put("teacherAttTable",teacherAttTable);
        List< ClassDiaryEntity > teacherTimeTable = classDiaryService.queryListTimeTableOfOurStudent(params);
        result.put("teacherTimeTable",teacherTimeTable);

        //教学内容相符率纵向比
        Map<String,List> timeLine=teacherPortraitService.getiMatchContentRateTimeLine(params);result.put("teacherContentPortrait",timeLine);
        //各学院教师平均课时数对比
        Map workLoadPointline=getAverageTeacherTotalOfCollege();result.put("workLoadPointline",workLoadPointline);
        //教学内容相符率纵向比
        Map<String,List> attendanceRateTime=attendenceChartsService.studentAttendanceRateTimeLine(params);result.put("attendanceRateTime",attendanceRateTime);
        List<StudentAttTable> studentAttTable=reportDao.getStudentAttTable(params);result.put("studentAttTable",studentAttTable);
        //出勤人数
        Integer chuqinNumber=reportDao.getChuqinNumber(params);result.put("chuqinNumber",chuqinNumber);
        //迟到人数
        Integer chidaoNumber= reportDao.getChidaoNumber(params);result.put("chidaoNumber",chidaoNumber);
        //旷课人数
        Integer kuangkeNumber= reportDao.getZaotuiNumber(params);result.put("kuangkeNumber",kuangkeNumber);
        //病假人数
        Integer bingjiaNumber= reportDao.getBingjiaNumber(params);result.put("bingjiaNumber",bingjiaNumber);
        //私假人数
        Integer sijiaNumber= reportDao.getSijiaNumber(params);result.put("sijiaNumber",sijiaNumber);
        //公假人数
        Integer gongjiaNumber= reportDao.getGongjiaNumber(params);result.put("gongjiaNumber",gongjiaNumber);


        return result;
    }

    @Override
    public Map getShekeJiChuResult(Map<String, Object> params) {
        String nowGrade= getNowGrade();//在校年级
        params.put("nowGrade",nowGrade);
        Map<String,Object> result=new HashMap();
        Integer classTotal=reportDao.getclassTotal(params);result.put("classTotal",classTotal);
        Integer allClassTotal=reportDao.getAllclassTotal(params);result.put("allClassTotal",allClassTotal);
        Integer studentTotal=reportDao.getStudentTotal(params);result.put("studentTotal",studentTotal);
        Integer allstudentTotal=reportDao.getAllstudentTotal(params);result.put("allstudentTotal",allstudentTotal);
        Integer teacherTotal=reportDao.getTeacherTotal(params);result.put("teacherTotal",teacherTotal);
        Integer allteacherTotal=reportDao.getAllteacherTotal(params);result.put("allteacherTotal",allteacherTotal);
        Integer chidaozaotuiTotal=reportDao.getChidaozaotuiTotal(params);result.put("chidaozaotuiTotal",chidaozaotuiTotal);
        List hasCourse =teacherEvaluationChartsService.getTeacherWorkEcharts(params);result.put("hasCourse",hasCourse);
        //出勤情况饼状图
        List<AttendanceDate> teacherAttendancePie=teacherPortraitService.getTeacherAttendancePie(params);result.put("teacherAttendancePie",teacherAttendancePie);
        //  Map<String,Object> hasCourseTime =teacherEvaluationChartsService.getTeacherWorkTimeRate(params);result.put("",);
        //迟到前十名
        Map  chidao=teacherPortraitService.getTeacherChidao(params);result.put("chidao",chidao);
        //早退前十名
        Map<String,List> zaotui=teacherPortraitService.getTeacherZaotui(params);result.put("zaotui",zaotui);
        Map<String,Object> rank =teacherEvaluationChartsService.getAverageTeacheingTimeRanking(params);result.put("rank",rank);

        Integer learningClassTotal=reportDao.getLearningClassTotal(params);result.put("learningClassTotal",learningClassTotal);
        Integer coureTotal=reportDao.getLearningCourseTotal(params);result.put("coureTotal",coureTotal);

        Double teacherTime=reportDao.getTeacherTime(params);result.put("teacherTime",teacherTime);
        Double allSchoolTeacherTime=reportDao.getAllSchoolTeacherTime(params);result.put("allSchoolTeacherTime",allSchoolTeacherTime);
        //相符率饼状图
        List<TeacherEvaltionPieEntity>  xiangfuRate=teacherEvaluationChartsService.getiMatchContentRate(params);result.put("xiangfuRate",xiangfuRate);
        //到课率
        Map  coincidenceRate=attendenceChartsService.studentAttendanceRate(params);result.put("coincidenceRate",coincidenceRate);
        //专业到课率排名
        Map<String,Object> pressionRate =attendenceChartsService.getAttendanceProfessionRankingFirstTen(params);result.put("pressionRate",pressionRate);
        //班级到课率排名
        Map<String,Object> ClassRate =attendenceChartsService.getAttendanceClassRankingFirstTen(params);result.put("ClassRate",ClassRate);

        //学院出勤情况横向比
        Map<String,Object> collegeTeacherEvaltion =teacherPortraitService.getTeacherAttendanceOfCollege01(params);result.put("collegeTeacherEvaltion",collegeTeacherEvaltion);
        //出勤情况纵向比
        Map<String,Object> teacherAttendanceTimePie =teacherPortraitService.getTecaherAttendanceCollegeHorizontalComparison(params);result.put("teacherAttendanceTimePie",teacherAttendanceTimePie);
        List< ClassDiaryEntity > teacherAttTable = classDiaryService.queryListChiDaoZaotui(params);result.put("teacherAttTable",teacherAttTable);
        List< ClassDiaryEntity > teacherTimeTable = classDiaryService.queryListTimeTable(params);
        result.put("teacherTimeTable",teacherTimeTable);

        //教学内容相符率纵向比
        Map<String,List> timeLine=teacherPortraitService.getiMatchContentRateTimeLine(params);result.put("teacherContentPortrait",timeLine);
        //各学院教师平均课时数对比
        Map workLoadPointline=getAverageTeacherTotalOfCollege();result.put("workLoadPointline",workLoadPointline);
        //教学内容相符率纵向比
        Map<String,List> attendanceRateTime=attendenceChartsService.studentAttendanceRateTimeLine(params);result.put("attendanceRateTime",attendanceRateTime);
        List<StudentAttTable> studentAttTable=reportDao.getStudentAttTable(params);result.put("studentAttTable",studentAttTable);
        //出勤人数
        Integer chuqinNumber=reportDao.getChuqinNumber(params);result.put("chuqinNumber",chuqinNumber);
        //迟到人数
        Integer chidaoNumber= reportDao.getChidaoNumber(params);result.put("chidaoNumber",chidaoNumber);
        //旷课人数
        Integer kuangkeNumber= reportDao.getZaotuiNumber(params);result.put("kuangkeNumber",kuangkeNumber);
        //病假人数
        Integer bingjiaNumber= reportDao.getBingjiaNumber(params);result.put("bingjiaNumber",bingjiaNumber);
        //私假人数
        Integer sijiaNumber= reportDao.getSijiaNumber(params);result.put("sijiaNumber",sijiaNumber);
        //公假人数
        Integer gongjiaNumber= reportDao.getGongjiaNumber(params);result.put("gongjiaNumber",gongjiaNumber);


        return result;
    }


    public String getNowGrade() {
        List<String> gradeList=reportDao.getNowGrade();
        StringBuffer sb=new StringBuffer();
        for(String g:gradeList)
        {
            sb.append("\'");
            sb.append(g);
            sb.append("\'");
            sb.append(",");
        }
        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }

    private Map getAverageTeacherTotalOfCollege()
    {
        Map<String,Object> map=new HashMap<>();
        List<String> names= new ArrayList<>();
        List<Double> totals= new ArrayList<>();
        List<workLoadPointline> workLoadPointline=reportDao.getAverageTeacherTotalOfCollege();
        for(workLoadPointline w:workLoadPointline)
        {

            names.add(w.getName());
            totals.add(w.getTotal());
        }
        map.put("xAxis",names);
        map.put("data",totals);
        return map;
    }
}
